import datetime
import struct
from data_reader.DataReader import DataReader


class KittiReader(DataReader):
    
    def __init__(self, data_dir):
        return DataReader.__init__(self, data_dir)


    def read_timestamp(self):
        time_str = self.timestamp_file_.readline()
        return float(time_str)/1e6

    def read_sweep(self):
        points = []

        f = open(self.data_dir_ + self.files_[self.index_], "rb")

        while True:
            x_str = f.read(4)
            if x_str == b'':
                break
            y_str = f.read(4)
            z_str = f.read(4)

            x = struct.unpack('f', x_str)[0]
            y = struct.unpack('f', y_str)[0]
            z = struct.unpack('f', z_str)[0]

            # read intensity data
            y_str = f.read(4)

            points.append((x, y, z))

        self.index_ += 1
        return points
